﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;

namespace DAO
{
    public class BanVeChuyenBay_DAO
    {
        public BindingList<BanVeChuyenBay_DTO> GetBanVeChuyenBayList()
        {
            BindingList<BanVeChuyenBay_DTO> listBanVeChuyenBay = new BindingList<BanVeChuyenBay_DTO>();
            try
            {
                QLCBDataContext context = new QLCBDataContext();
                var query = from ve in context.VeChuyenBays
                            join hk in context.HanhKhaches on ve.MaHanhKhach equals hk.MaHanhKhach
                            join hv in context.HangVes on ve.MaHangVe equals hv.MaHangVe
                            select new
                            {
                                ve.MaVe,
                                ve.MaChuyenBay,
                                hv.MaHangVe,
                                hk.MaHanhKhach,
                                hk.TenHanhKhach,
                                hk.CMND,
                                hk.DienThoai,
                                ve.GiaTien,
                            };
                int mSTT = 1;
                foreach (var cb in query)
                {
                    BanVeChuyenBay_DTO DTO = new BanVeChuyenBay_DTO();
                    DTO.STT = mSTT;
                    DTO.MaVe = cb.MaVe;
                    DTO.ChuyenBay = cb.MaChuyenBay;
                    DTO.MaHangVe = cb.MaHangVe;
                    DTO.MaHanhKhach = cb.MaHanhKhach;
                    DTO.TenHanhKhach = cb.TenHanhKhach;
                    DTO.CMND = cb.CMND;
                    DTO.DienThoai = cb.DienThoai;
                    DTO.GiaTien = (float)cb.GiaTien;
                    listBanVeChuyenBay.Add(DTO);
                    mSTT++;
                }
            }
            catch (System.Exception ex)
            {
                string str = ex.Message;
            }
            return listBanVeChuyenBay;
        }
    }
}
